package com.sikao.app.app;

import android.app.Application;
import android.app.Service;
import android.graphics.BitmapFactory;
import android.os.Vibrator;

import com.baidu.mapapi.SDKInitializer;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.download.BaseImageDownloader;
import com.sikao.app.service.LocationService;

/**
 * Created by y50 on 2016/4/15.
 */
public class MyApplication extends Application{

	/**对外提供整个应用生命周期的Context**/
	private static MyApplication instance;
	public LocationService locationService;
	public Vibrator mVibrator;
	@Override
	public void onCreate() {
		super.onCreate();
		instance = this;
		init();
	}
	/**
	 * 初始化工作
	 */
	private void init(){
		//初始化定位sdk，建议在Application中创建
		locationService = new LocationService(instance);
		mVibrator =(Vibrator)instance.getSystemService(Service.VIBRATOR_SERVICE);
		SDKInitializer.initialize(instance);
		//imageloader初始化
		DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() //
				.cacheInMemory(true) //
				.cacheOnDisk(true) //
				.build();//
		ImageLoaderConfiguration config = new ImageLoaderConfiguration//
				.Builder(getApplicationContext())//
				.defaultDisplayImageOptions(defaultOptions)//
				.writeDebugLogs()//
				.imageDownloader(new BaseImageDownloader(instance,40000,40000))
				.build();//
				//.discCacheSize(50 * 1024 * 1024)//
				//.discCacheFileCount(100)// 缓存一百张图片
		ImageLoader.getInstance().init(config);
	}
	public static MyApplication getInstance(){
		return instance;
	}
}
